package com.cookor.poi.modules.phy.service;

import com.cookor.poi.common.persistence.DataEntity;
import com.cookor.poi.common.persistence.Page;
import com.cookor.poi.common.service.CrudService;
import com.cookor.poi.common.utils.DateUtils;
import com.cookor.poi.modules.phy.dao.TSchedueDao;
import com.cookor.poi.modules.phy.dto.TSchedueDto;
import com.cookor.poi.modules.phy.dto.TSchedueMpDto;
import com.cookor.poi.modules.phy.entity.TBookNo;
import com.cookor.poi.modules.phy.entity.TDoctor;
import com.cookor.poi.modules.phy.entity.TOrder;
import com.cookor.poi.modules.phy.entity.TSchedue;
import com.cookor.poi.modules.phy.entity.TShift;
import com.cookor.poi.modules.phy.entity.TStock;
import com.cookor.poi.modules.phy.entity.TTempNotice;
import com.cookor.poi.modules.weixin.account.PlatformAccount;
import com.cookor.poi.modules.weixin.entity.TWeixinConfig;
import com.cookor.poi.modules.weixin.open.WxOpenUtil;
import com.cookor.poi.modules.weixin.service.TWeixinConfigService;
import com.cookor.poi.modules.weixin.utils.TempNoticeUtil;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true)
public class TSchedueService extends CrudService<TSchedueDao, TSchedue> {
  @Autowired
  private TBookNoService tBookNoService;
  
  @Autowired
  private TShiftService tShiftService;
  
  @Autowired
  private TDoctorService tDoctorService;
  
  @Autowired
  private TStockService tStockService;
  
  @Autowired
  @Lazy
  private TOrderService tOrderService;
  
  @Autowired
  @Lazy
  private TTempNoticeService tTempNoticeService;
  
  @Autowired
  @Lazy
  private TWeixinConfigService tWeixinConfigService;
  
  public TSchedue get(String id) {
    return (TSchedue)super.get(id);
  }
  
  public List<TSchedue> findList(TSchedue tSchedue) {
    return super.findList( tSchedue);
  }
  
  public Page<TSchedue> findPage(Page<TSchedue> page, TSchedue tSchedue) {
    return super.findPage(page,  tSchedue);
  }
  
  @Transactional(readOnly = false)
  public void save(TSchedue tSchedue) {
    super.save( tSchedue);
  }
  
  @Transactional(readOnly = false, rollbackFor = {Exception.class})
  public void mySave(TSchedue tSchedue) throws Exception {
    tSchedueHandle(tSchedue);
    super.save( tSchedue);
  }
  
  @Transactional(readOnly = false)
  public void delete(TSchedue tSchedue) {
    super.delete( tSchedue);
  }
  
  @Transactional(readOnly = false)
  public void trueDele(Integer tenantId, Integer doctorId, Integer year, Integer month) {
    ((TSchedueDao)this.dao).trueDele(tenantId, doctorId, year, month);
  }
  
  @Transactional(readOnly = false, rollbackFor = {Exception.class})
  public void tSchedueHandle(TSchedue newT) throws Exception {
    TShift tShift = new TShift();
    tShift.setTenantId(newT.getTenantId());
    tShift.setShiftName(Integer.valueOf(TShift.am));
    List<TShift> list = this.tShiftService.findList(tShift);
    if (list.size() != 1)
      throw new Exception("该机构未设置上午班次！"); 
    String amBeginDate = ((TShift)list.get(0)).getBeginDate();
    String amEndDate = ((TShift)list.get(0)).getEndDate();
    tShift = new TShift();
    tShift.setTenantId(newT.getTenantId());
    tShift.setShiftName(Integer.valueOf(TShift.pm));
    list = this.tShiftService.findList(tShift);
    if (list.size() != 1)
      throw new Exception("该机构未设置下午班次！"); 
    String pmBeginDate = ((TShift)list.get(0)).getBeginDate();
    String pmEndDate = ((TShift)list.get(0)).getEndDate();
    TDoctor tDoctor = this.tDoctorService.get(newT.getDoctorId().toString());
    TSchedue oldT = get(newT.getId());
    Integer month = newT.getScheduleMonth();
    Integer year = newT.getScheduleYear();
    List<TSchedueDto> changeList = getChangeList(oldT, newT);
    List<TBookNo> bookNoList = new ArrayList<>();
    int i = 1;
    TOrder queryOrder = new TOrder();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    TTempNotice tempNotice = this.tTempNoticeService.getByParam(newT.getTenantId(), Integer.valueOf(TTempNotice.appointStop));
    TWeixinConfig wc = this.tWeixinConfigService.findByTenantId(newT.getTenantId());
    for (TSchedueDto dto : changeList) {
      queryOrder.setTenantId(newT.getTenantId());
      queryOrder.setDoctorId(newT.getDoctorId());
      queryOrder.setBookDate(sdf.parse(year + "-" + month + "-" + dto.getDay()));
      List<TOrder> orderList = this.tOrderService.findList(queryOrder);
      for (TOrder order : orderList) {
        if ((dto.getWeekStatus().intValue() == 4 || (dto.getWeekStatus().intValue() != 3 && dto.getWeekStatus() != order.getBookDateType())) && 
          order.getStatus().intValue() != 11) {
          order.setStatus(Integer.valueOf(11));
          order.setRemarks("医生坐诊日期变更");
          this.tOrderService.save(order);
          if (tempNotice != null && tempNotice.getStatus().intValue() == 1) {
            String data = TempNoticeUtil.getAppointStop(tempNotice.getTempId(), order);
            PlatformAccount account = new PlatformAccount(wc);
            String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + account.getAccessToken();
            WxOpenUtil.httpPost(url, data);
          } 
        } 
      } 
      this.tBookNoService.deleteByParam(newT.getTenantId(), null, newT.getDoctorId(), year, month, dto.getDay());
      if (dto.getWeekStatus().intValue() == 4)
        continue; 
      if (dto.getWeekStatus().intValue() != 2) {
        List<String> times = DateUtils.spliteDate(amBeginDate, amEndDate, dto.getAm());
        i = 1;
        for (String time : times) {
          bookNoList.add(TSchedueTemplateService.bookNoHandle(dto.getDay(), month, year, newT.getDoctorId(), newT
                .getTenantId(), tDoctor.getOfficeId(), time, 1, i));
          i++;
        } 
      } 
      if (dto.getWeekStatus().intValue() != 1) {
        List<String> times = DateUtils.spliteDate(pmBeginDate, pmEndDate, dto.getPm());
        i = 1;
        for (String time : times) {
          bookNoList.add(TSchedueTemplateService.bookNoHandle(dto.getDay(), month, year, newT.getDoctorId(), newT
                .getTenantId(), tDoctor.getOfficeId(), time, 2, i));
          i++;
        } 
      } 
    } 
    if (!bookNoList.isEmpty())
      this.tBookNoService.batchInsert(bookNoList); 
  }
  
  public List<TSchedueDto> getChangeList(TSchedue oldT, TSchedue newT) {
    List<TSchedueDto> list = new ArrayList<>();
    if (oldT.getFirst() != newT.getFirst() || oldT.getAmFirst() != newT.getAmFirst() || oldT.getPmFirst() != newT.getPmFirst()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(1));
      dto.setAm(newT.getAmFirst());
      dto.setPm(newT.getPmFirst());
      dto.setWeekStatus(newT.getFirst());
      list.add(dto);
    } 
    if (oldT.getSecond() != newT.getSecond() || oldT.getAmSecond() != newT.getAmSecond() || oldT.getPmSecond() != newT.getPmSecond()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(2));
      dto.setAm(newT.getAmSecond());
      dto.setPm(newT.getPmSecond());
      dto.setWeekStatus(newT.getSecond());
      list.add(dto);
    } 
    if (oldT.getThird() != newT.getThird() || oldT.getAmThird() != newT.getAmThird() || oldT.getPmThird() != newT.getPmThird()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(3));
      dto.setAm(newT.getAmThird());
      dto.setPm(newT.getPmThird());
      dto.setWeekStatus(newT.getThird());
      list.add(dto);
    } 
    if (oldT.getFourth() != newT.getFourth() || oldT.getAmFourth() != newT.getAmFourth() || oldT.getPmFourth() != newT.getPmFourth()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(4));
      dto.setAm(newT.getAmFourth());
      dto.setPm(newT.getPmFourth());
      dto.setWeekStatus(newT.getFourth());
      list.add(dto);
    } 
    if (oldT.getFifth() != newT.getFifth() || oldT.getAmFifth() != newT.getAmFifth() || oldT.getPmFifth() != newT.getPmFifth()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(5));
      dto.setAm(newT.getAmFifth());
      dto.setPm(newT.getPmFifth());
      dto.setWeekStatus(newT.getFifth());
      list.add(dto);
    } 
    if (oldT.getSixth() != newT.getSixth() || oldT.getAmSixth() != newT.getAmSixth() || oldT.getPmSixth() != newT.getPmSixth()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(6));
      dto.setAm(newT.getAmSixth());
      dto.setPm(newT.getPmSixth());
      dto.setWeekStatus(newT.getSixth());
      list.add(dto);
    } 
    if (oldT.getSeventh() != newT.getSeventh() || oldT.getAmSeventh() != newT.getAmSeventh() || oldT.getPmSeventh() != newT.getPmSeventh()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(7));
      dto.setAm(newT.getAmSeventh());
      dto.setPm(newT.getPmSeventh());
      dto.setWeekStatus(newT.getSeventh());
      list.add(dto);
    } 
    if (oldT.getEighth() != newT.getEighth() || oldT.getAmEighth() != newT.getAmEighth() || oldT.getPmEighth() != newT.getPmEighth()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(8));
      dto.setAm(newT.getAmEighth());
      dto.setPm(newT.getPmEighth());
      dto.setWeekStatus(newT.getEighth());
      list.add(dto);
    } 
    if (oldT.getNinth() != newT.getNinth() || oldT.getAmNinth() != newT.getAmNinth() || oldT.getPmNinth() != newT.getPmNinth()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(9));
      dto.setAm(newT.getAmNinth());
      dto.setPm(newT.getPmNinth());
      dto.setWeekStatus(newT.getNinth());
      list.add(dto);
    } 
    if (oldT.getTenth() != newT.getTenth() || oldT.getAmTenth() != newT.getAmTenth() || oldT.getPmTenth() != newT.getPmTenth()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(10));
      dto.setAm(newT.getAmTenth());
      dto.setPm(newT.getPmTenth());
      dto.setWeekStatus(newT.getTenth());
      list.add(dto);
    } 
    if (oldT.getEleventh() != newT.getEleventh() || oldT.getAmEleventh() != newT.getAmEleventh() || oldT.getPmEleventh() != newT.getPmEleventh()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(11));
      dto.setAm(newT.getAmEleventh());
      dto.setPm(newT.getPmEleventh());
      dto.setWeekStatus(newT.getEleventh());
      list.add(dto);
    } 
    if (oldT.getTwelfth() != newT.getTwelfth() || oldT.getAmTwelfth() != newT.getAmTwelfth() || oldT.getPmTwelfth() != newT.getPmTwelfth()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(12));
      dto.setAm(newT.getAmTwelfth());
      dto.setPm(newT.getPmTwelfth());
      dto.setWeekStatus(newT.getTwelfth());
      list.add(dto);
    } 
    if (oldT.getThirteenth() != newT.getThirteenth() || oldT.getAmThirteenth() != newT.getAmThirteenth() || oldT.getPmThirteenth() != newT.getPmThirteenth()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(13));
      dto.setAm(newT.getAmThirteenth());
      dto.setPm(newT.getPmThirteenth());
      dto.setWeekStatus(newT.getThirteenth());
      list.add(dto);
    } 
    if (oldT.getFourteenth() != newT.getFourteenth() || oldT.getAmFourteenth() != newT.getAmFourteenth() || oldT.getPmFourteenth() != newT.getPmFourteenth()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(14));
      dto.setAm(newT.getAmFourteenth());
      dto.setPm(newT.getPmFourteenth());
      dto.setWeekStatus(newT.getFourteenth());
      list.add(dto);
    } 
    if (oldT.getFifteenth() != newT.getFifteenth() || oldT.getAmFifteenth() != newT.getAmFifteenth() || oldT.getPmFifteenth() != newT.getPmFifteenth()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(15));
      dto.setAm(newT.getAmFifteenth());
      dto.setPm(newT.getPmFifteenth());
      dto.setWeekStatus(newT.getFifteenth());
      list.add(dto);
    } 
    if (oldT.getSixteenth() != newT.getSixteenth() || oldT.getAmSixteenth() != newT.getAmSixteenth() || oldT.getPmSixteenth() != newT.getSixteenth()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(16));
      dto.setAm(newT.getAmSixteenth());
      dto.setPm(newT.getPmSixteenth());
      dto.setWeekStatus(newT.getSixteenth());
      list.add(dto);
    } 
    if (oldT.getSeventeenth() != newT.getSixteenth() || oldT.getAmSixteenth() != newT.getAmSeventeenth() || oldT.getPmSeventeenth() != newT.getPmSeventeenth()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(17));
      dto.setAm(newT.getAmSeventeenth());
      dto.setPm(newT.getPmSeventeenth());
      dto.setWeekStatus(newT.getSeventeenth());
      list.add(dto);
    } 
    if (oldT.getEighteenth() != newT.getEighteenth() || oldT.getAmEighteenth() != newT.getAmEighteenth() || oldT.getPmEighteenth() != newT.getPmEighteenth()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(18));
      dto.setAm(newT.getAmEighteenth());
      dto.setPm(newT.getPmEighteenth());
      dto.setWeekStatus(newT.getEighteenth());
      list.add(dto);
    } 
    if (oldT.getNineteenth() != newT.getNineteenth() || oldT.getAmNineteenth() != newT.getAmNineteenth() || oldT.getPmNineteenth() != newT.getPmNineteenth()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(19));
      dto.setAm(newT.getAmEighteenth());
      dto.setPm(newT.getPmEighteenth());
      dto.setWeekStatus(newT.getEighteenth());
      list.add(dto);
    } 
    if (oldT.getTwentieth() != newT.getTwentieth() || oldT.getAmTwentieth() != newT.getAmTwentieth() || oldT.getPmTwentieth() != newT.getPmTwentieth()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(20));
      dto.setAm(newT.getAmTwentieth());
      dto.setPm(newT.getPmTwentieth());
      dto.setWeekStatus(newT.getTwentieth());
      list.add(dto);
    } 
    if (oldT.getTwentyFirst() != newT.getTwentyFirst() || oldT.getAmTwentyFirst() != newT.getAmTwentyFirst() || oldT.getPmTwentyFirst() != newT.getPmTwentyFirst()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(21));
      dto.setAm(newT.getAmTwentyFirst());
      dto.setPm(newT.getPmTwentyFirst());
      dto.setWeekStatus(newT.getTwentyFirst());
      list.add(dto);
    } 
    if (oldT.getTwentySecond() != newT.getTwentySecond() || oldT.getAmTwentySecond() != newT.getAmTwentySecond() || oldT.getPmTwentySecond() != newT.getPmTwentySecond()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(22));
      dto.setAm(newT.getAmTwentySecond());
      dto.setPm(newT.getPmTwentySecond());
      dto.setWeekStatus(newT.getTwentySecond());
      list.add(dto);
    } 
    if (oldT.getTwentyThird() != newT.getTwentyThird() || oldT.getAmTwentyThird() != newT.getAmTwentyThird() || oldT.getPmTwentyThird() != newT.getPmTwentyThird()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(23));
      dto.setAm(newT.getAmTwentyThird());
      dto.setPm(newT.getPmTwentyThird());
      dto.setWeekStatus(newT.getTwentyThird());
      list.add(dto);
    } 
    if (oldT.getTwentyFourth() != newT.getTwentyFourth() || oldT.getAmTwentyFourth() != newT.getAmTwentyFourth() || oldT.getPmTwentyFourth() != newT.getPmTwentyFourth()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(24));
      dto.setAm(newT.getAmTwentyFourth());
      dto.setPm(newT.getPmTwentyFourth());
      dto.setWeekStatus(newT.getTwentyFourth());
      list.add(dto);
    } 
    if (oldT.getTwentyFifth() != newT.getTwentyFifth() || oldT.getAmTwentyFifth() != newT.getAmTwentyFifth() || oldT.getPmTwentyFifth() != newT.getPmTwentyFifth()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(25));
      dto.setAm(newT.getAmTwentyFifth());
      dto.setPm(newT.getPmTwentyFifth());
      dto.setWeekStatus(newT.getTwentyFifth());
      list.add(dto);
    } 
    if (oldT.getTwentySixth() != newT.getTwentySixth() || oldT.getAmTwentySixth() != newT.getAmTwentySixth() || oldT.getPmTwentySixth() != newT.getPmTwentySixth()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(26));
      dto.setAm(newT.getAmTwentySixth());
      dto.setPm(newT.getPmTwentySixth());
      dto.setWeekStatus(newT.getTwentySixth());
      list.add(dto);
    } 
    if (oldT.getTwentySeventh() != newT.getTwentySeventh() || oldT.getAmTwentySeventh() != newT.getAmTwentySeventh() || oldT.getPmTwentySeventh() != newT.getPmTwentySeventh()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(27));
      dto.setAm(newT.getAmTwentySeventh());
      dto.setPm(newT.getPmTwentySeventh());
      dto.setWeekStatus(newT.getTwentySeventh());
      list.add(dto);
    } 
    if (oldT.getTwentyEighth() != newT.getTwentyEighth() || oldT.getAmTwentyEighth() != newT.getAmTwentyEighth() || oldT.getPmTwentyEighth() != newT.getPmTwentyEighth()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(28));
      dto.setAm(newT.getAmTwentyEighth());
      dto.setPm(newT.getPmTwentyEighth());
      dto.setWeekStatus(newT.getTwentyEighth());
      list.add(dto);
    } 
    if (oldT.getTwentyNinth() != newT.getTwentyNinth() || oldT.getAmTwentyNinth() != newT.getAmTwentyNinth() || oldT.getPmTwentyNinth() != newT.getPmTwentyNinth()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(29));
      dto.setAm(newT.getAmTwentyNinth());
      dto.setPm(newT.getPmTwentyNinth());
      dto.setWeekStatus(newT.getTwentyNinth());
      list.add(dto);
    } 
    if (oldT.getThirtieth() != newT.getThirtieth() || oldT.getAmThirtieth() != newT.getAmThirtieth() || oldT.getPmThirtieth() != newT.getPmThirtieth()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(30));
      dto.setAm(newT.getAmThirtieth());
      dto.setPm(newT.getPmThirtieth());
      dto.setWeekStatus(newT.getThirtieth());
      list.add(dto);
    } 
    if (oldT.getThirtyFirst() != newT.getThirtyFirst() || oldT.getAmThirtyFirst() != newT.getAmThirtyFirst() || oldT.getPmThirtyFirst() != newT.getPmThirtyFirst()) {
      TSchedueDto dto = new TSchedueDto();
      dto.setDay(Integer.valueOf(31));
      dto.setAm(newT.getAmThirtyFirst());
      dto.setPm(newT.getPmThirtyFirst());
      dto.setWeekStatus(newT.getThirtyFirst());
      list.add(dto);
    } 
    return list;
  }
  
  public TSchedue findByDoctorId(Integer tenantId, Integer doctorId, Integer year, Integer month) {
    return ((TSchedueDao)this.dao).findByDoctorId(tenantId, doctorId, year, month);
  }
  
  public List<TSchedueMpDto> format(TSchedue tSchedue, TSchedue next) {
    List<TSchedueMpDto> list = new ArrayList<>();
    Calendar now = Calendar.getInstance();
    Calendar c = Calendar.getInstance();
    Calendar ca = Calendar.getInstance();
    int block = 6;
    long distance = (c.getTimeInMillis() - now.getTimeInMillis()) / 1000L / 60L / 60L / 24L;
    int flag = 0;
    while (distance < 8L) {
      c.add(5, 1);
      int i = c.get(5);
      distance = (c.getTimeInMillis() - now.getTimeInMillis()) / 1000L / 60L / 60L / 24L;
      if (tSchedue.getScheduleYear().intValue() != c.get(1))
        tSchedue = next; 
      TSchedueMpDto dto = new TSchedueMpDto();
      dto.setYear(Integer.valueOf(c.get(1)));
      dto.setMonth(Integer.valueOf(c.get(2) + 1));
      dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
      if (flag == 1)
        break; 
      if (distance > block) {
        flag = 1;
        ca.setTime(c.getTime());
        ca.add(6, block * -1);
        dto.setBlockYear(Integer.valueOf(ca.get(1)));
        dto.setBlockMonth(Integer.valueOf(ca.get(2) + 1));
        dto.setBlockDay(Integer.valueOf(ca.get(5)));
      } 
      dto.setBlock(Integer.valueOf(flag));
      if (i == 1) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getFirst().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmFirst());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmFirst());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getFirst().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getFirst()));
        dto.setStock((tSchedue.getFirst().intValue() == 1) ? tSchedue.getAmFirst() : tSchedue.getPmFirst());
        list.add(dto);
        continue;
      } 
      if (i == 2) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getSecond().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmSecond());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmSecond());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getSecond().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getSecond()));
        dto.setStock((tSchedue.getSecond().intValue() == 1) ? tSchedue.getAmSecond() : tSchedue.getPmSecond());
        list.add(dto);
        continue;
      } 
      if (i == 3) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getThird().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmThird());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmThird());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getThird().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getThird()));
        dto.setStock((tSchedue.getThird().intValue() == 1) ? tSchedue.getAmThird() : tSchedue.getPmThird());
        list.add(dto);
        continue;
      } 
      if (i == 4) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getFourth().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmFourth());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmFourth());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getFourth().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getFourth()));
        dto.setStock((tSchedue.getFourth().intValue() == 1) ? tSchedue.getAmFourth() : tSchedue.getPmFourth());
        list.add(dto);
        continue;
      } 
      if (i == 5) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getFifth().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmFifth());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmFifth());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getFifth().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getFifth()));
        dto.setStock((tSchedue.getFifth().intValue() == 1) ? tSchedue.getAmFifth() : tSchedue.getPmFifth());
        list.add(dto);
        continue;
      } 
      if (i == 6) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getSixth().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmSixth());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmSixth());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getSixth().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getSixth()));
        dto.setStock((tSchedue.getSixth().intValue() == 1) ? tSchedue.getAmSixth() : tSchedue.getPmSixth());
        list.add(dto);
        continue;
      } 
      if (i == 7) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getSeventh().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmSeventh());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmSeventh());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getSeventh().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getSeventh()));
        dto.setStock((tSchedue.getSeventh().intValue() == 1) ? tSchedue.getAmSeventh() : tSchedue.getPmSeventh());
        list.add(dto);
        continue;
      } 
      if (i == 8) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getEighth().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmEighth());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmEighth());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getEighth().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getEighth()));
        dto.setStock((tSchedue.getEighth().intValue() == 1) ? tSchedue.getAmEighth() : tSchedue.getPmEighth());
        list.add(dto);
        continue;
      } 
      if (i == 9) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getNinth().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmNinth());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmNinth());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getNinth().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getNinth()));
        dto.setStock((tSchedue.getNinth().intValue() == 1) ? tSchedue.getAmNinth() : tSchedue.getPmNinth());
        list.add(dto);
        continue;
      } 
      if (i == 10) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getTenth().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmTenth());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmTenth());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getTenth().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getTenth()));
        dto.setStock((tSchedue.getTenth().intValue() == 1) ? tSchedue.getAmTenth() : tSchedue.getPmTenth());
        list.add(dto);
        continue;
      } 
      if (i == 11) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getEleventh().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmEleventh());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmEleventh());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getEleventh().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getEleventh()));
        dto.setStock((tSchedue.getEleventh().intValue() == 1) ? tSchedue.getAmEleventh() : tSchedue.getPmEleventh());
        list.add(dto);
        continue;
      } 
      if (i == 12) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getTwelfth().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmTwelfth());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmTwelfth());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getTwelfth().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getTwelfth()));
        dto.setStock((tSchedue.getTwelfth().intValue() == 1) ? tSchedue.getAmTwelfth() : tSchedue.getPmTwelfth());
        list.add(dto);
        continue;
      } 
      if (i == 13) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getThirteenth().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmThirteenth());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmThirteenth());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getThirteenth().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getThirteenth()));
        dto.setStock((tSchedue.getThirteenth().intValue() == 1) ? tSchedue.getAmThirteenth() : tSchedue.getPmThirteenth());
        list.add(dto);
        continue;
      } 
      if (i == 14) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getFourteenth().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmFourteenth());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmFourteenth());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getFourteenth().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getFourteenth()));
        dto.setStock((tSchedue.getFourteenth().intValue() == 1) ? tSchedue.getAmFourteenth() : tSchedue.getPmFourteenth());
        list.add(dto);
        continue;
      } 
      if (i == 15) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getFifteenth().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmFifteenth());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmFifteenth());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getFifteenth().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getFifteenth()));
        dto.setStock((tSchedue.getFifteenth().intValue() == 1) ? tSchedue.getAmFifteenth() : tSchedue.getPmFifteenth());
        list.add(dto);
        continue;
      } 
      if (i == 16) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getSixteenth().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmSixteenth());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmSixteenth());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getSixteenth().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getSixteenth()));
        dto.setStock((tSchedue.getSixteenth().intValue() == 1) ? tSchedue.getAmSixteenth() : tSchedue.getPmSixteenth());
        list.add(dto);
        continue;
      } 
      if (i == 17) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getSeventeenth().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmSeventeenth());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmSeventeenth());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getSeventeenth().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getSeventeenth()));
        dto.setStock((tSchedue.getSeventeenth().intValue() == 1) ? tSchedue.getAmSeventeenth() : tSchedue.getPmSeventeenth());
        list.add(dto);
        continue;
      } 
      if (i == 18) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getEighteenth().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmEighteenth());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmEighteenth());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getEighteenth().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getEighteenth()));
        dto.setStock((tSchedue.getEighteenth().intValue() == 1) ? tSchedue.getAmEighteenth() : tSchedue.getPmEighteenth());
        list.add(dto);
        continue;
      } 
      if (i == 19) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getNineteenth().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmNineteenth());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmNineteenth());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getNineteenth().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getNineteenth()));
        dto.setStock((tSchedue.getNineteenth().intValue() == 1) ? tSchedue.getAmNineteenth() : tSchedue.getPmNineteenth());
        list.add(dto);
        continue;
      } 
      if (i == 20) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getTwentieth().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmTwentieth());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmTwentieth());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getTwentieth().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getTwentieth()));
        dto.setStock((tSchedue.getTwentieth().intValue() == 1) ? tSchedue.getAmTwentieth() : tSchedue.getPmTwentieth());
        list.add(dto);
        continue;
      } 
      if (i == 21) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getTwentyFirst().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmTwentyFirst());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmTwentyFirst());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getTwentyFirst().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getTwentyFirst()));
        dto.setStock((tSchedue.getTwentyFirst().intValue() == 1) ? tSchedue.getAmTwentyFirst() : tSchedue.getPmTwentyFirst());
        list.add(dto);
        continue;
      } 
      if (i == 22) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getTwentySecond().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmTwentySecond());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmTwentySecond());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getTwentySecond().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getTwentySecond()));
        dto.setStock((tSchedue.getTwentySecond().intValue() == 1) ? tSchedue.getAmTwentySecond() : tSchedue.getPmTwentySecond());
        list.add(dto);
        continue;
      } 
      if (i == 23) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getTwentyThird().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmTwentyThird());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmTwentyThird());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getTwentyThird().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getTwentyThird()));
        dto.setStock((tSchedue.getTwentyThird().intValue() == 1) ? tSchedue.getAmTwentyThird() : tSchedue.getPmTwentyThird());
        list.add(dto);
        continue;
      } 
      if (i == 24) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getTwentyFourth().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmTwentyFourth());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmTwentyFourth());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getTwentyFourth().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getTwentyFourth()));
        dto.setStock((tSchedue.getTwentyFourth().intValue() == 1) ? tSchedue.getAmTwentyFourth() : tSchedue.getPmTwentyFourth());
        list.add(dto);
        continue;
      } 
      if (i == 25) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getTwentyFifth().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmTwentyFifth());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmTwentyFifth());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getTwentyFifth().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getTwentyFifth()));
        dto.setStock((tSchedue.getTwentyFifth().intValue() == 1) ? tSchedue.getAmTwentyFifth() : tSchedue.getPmTwentyFifth());
        list.add(dto);
        continue;
      } 
      if (i == 26) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getTwentySixth().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmTwentySixth());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmTwentySixth());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getTwentySixth().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getTwentySixth()));
        dto.setStock((tSchedue.getTwentySixth().intValue() == 1) ? tSchedue.getAmTwentySixth() : tSchedue.getPmTwentySixth());
        list.add(dto);
        continue;
      } 
      if (i == 27) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getTwentySeventh().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmTwentySeventh());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmTwentySeventh());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getFifth().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getTwentySeventh()));
        dto.setStock((tSchedue.getTwentySeventh().intValue() == 1) ? tSchedue.getAmTwentySeventh() : tSchedue.getPmTwentySeventh());
        list.add(dto);
        continue;
      } 
      if (i == 28) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getTwentyEighth().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmTwentyEighth());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmTwentyEighth());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getTwentyEighth().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getTwentyEighth()));
        dto.setStock((tSchedue.getTwentyEighth().intValue() == 1) ? tSchedue.getAmTwentyEighth() : tSchedue.getPmTwentyEighth());
        list.add(dto);
        continue;
      } 
      if (i == 29) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getTwentyNinth() == null)
          continue; 
        if (tSchedue.getTwentyNinth().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmTwentyNinth());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmTwentyNinth());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getTwentyNinth().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getTwentyNinth()));
        dto.setStock((tSchedue.getTwentyNinth().intValue() == 1) ? tSchedue.getAmTwentyNinth() : tSchedue.getPmTwentyNinth());
        list.add(dto);
        continue;
      } 
      if (i == 30) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getThirtieth() == null)
          continue; 
        if (tSchedue.getThirtieth().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmThirtieth());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmThirtieth());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getThirtieth().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getThirtieth()));
        dto.setStock((tSchedue.getThirtieth().intValue() == 1) ? tSchedue.getAmThirtieth() : tSchedue.getPmThirtieth());
        list.add(dto);
        continue;
      } 
      if (i == 31) {
        dto.setDay(Integer.valueOf(i));
        if (tSchedue.getThirtyFirst() == null)
          continue; 
        if (tSchedue.getThirtyFirst().intValue() == 3) {
          dto.setTimeType("上午");
          dto.setStock(tSchedue.getAmThirtyFirst());
          list.add(dto);
          if (flag == 1)
            break; 
          dto = new TSchedueMpDto();
          dto.setDay(Integer.valueOf(i));
          dto.setYear(Integer.valueOf(c.get(1)));
          dto.setMonth(Integer.valueOf(c.get(2) + 1));
          dto.setWeek(getWeekStr(Integer.valueOf(c.get(7))));
          dto.setBlock(Integer.valueOf(flag));
          dto.setTimeType("下午");
          dto.setStock(tSchedue.getPmThirtieth());
          list.add(dto);
          continue;
        } 
        if (tSchedue.getThirtyFirst().intValue() == 4)
          continue; 
        dto.setTimeType(getTimeTypeStr(tSchedue.getThirtieth()));
        dto.setStock((tSchedue.getThirtieth().intValue() == 1) ? tSchedue.getAmThirtyFirst() : tSchedue.getPmThirtieth());
        list.add(dto);
      } 
    } 
    return list;
  }
  
  private String getWeekStr(Integer nowWeek) {
    if (nowWeek.intValue() == 1)
      return "周日"; 
    if (nowWeek.intValue() == 2)
      return "周一"; 
    if (nowWeek.intValue() == 3)
      return "周二"; 
    if (nowWeek.intValue() == 4)
      return "周三"; 
    if (nowWeek.intValue() == 5)
      return "周四"; 
    if (nowWeek.intValue() == 6)
      return "周五"; 
    if (nowWeek.intValue() == 7)
      return "周六"; 
    return null;
  }
  
  private String getTimeTypeStr(Integer type) {
    if (type.intValue() == 1)
      return "上午"; 
    if (type.intValue() == 2)
      return "下午"; 
    return null;
  }
  
  public List<TSchedueMpDto> getMpDate(TDoctor tDoctor, TSchedue now, TSchedue next) throws Exception {
    if (tDoctor.getBookStatus().intValue() == 0 || tDoctor.getDimission().intValue() == 1)
      return new ArrayList<>(); 
    List<TSchedueMpDto> format = format(now, next);
    for (TSchedueMpDto dto : format) {
      if (dto.getTimeType() == null)
        continue; 
      int timeType = dto.getTimeType().equals("上午") ? 1 : 2;
      List<TStock> stockList = this.tStockService.getListByParam(Integer.valueOf(Integer.parseInt(now.getTenant().getId())), 
          Integer.valueOf(Integer.parseInt(now.getDoctor().getId())), dto.getYear(), dto.getMonth());
      for (TStock stock : stockList) {
        if (stock.getStockDay() == dto.getDay() && stock.getType().intValue() == timeType)
          dto.setStock(stock.getStock()); 
      } 
    } 
    return format;
  }
  
  public List<TSchedue> findForMp(TSchedue schedue) {
    return ((TSchedueDao)this.dao).findForMp(schedue);
  }
}
